package com.bizihang.controller.async;

import lombok.extern.slf4j.Slf4j;
import org.springframework.stereotype.Component;

/**
 * @author 毕子航 951755883@qq.com
 * @date 2018/08/15
 */
@Slf4j
@Component
public class MockQueue {

	String placeOrder;
	String completeOrder;

	public String getPlaceOrder() {
		return placeOrder;
	}

	public void setPlaceOrder(String placeOrder) {
		//处理下单请求：应用2，睡眠1s,模拟保存到数据库;处理完成后结果保存到消息队列(这里使用completeOrder存放处理的结果)
		new Thread(() -> {
			log.info("接到下单请求：{}", placeOrder);
			try {
				Thread.sleep(1000L);
			} catch (InterruptedException e) {
				e.printStackTrace();
			}
			//应用2：保存结果到消息队列
			this.completeOrder = placeOrder;
			log.info("下单请求处理完毕：{}", this.completeOrder);
		}).start();
	}


	public String getCompleteOrder() {
		return completeOrder;
	}

	public void setCompleteOrder(String completeOrder) {
		this.completeOrder = completeOrder;
	}
}
